package com.nineclock.system.controller;

import com.nineclock.attendance.dto.DepartmentOrUserSimpleDTO;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.system.pojo.SysCompanyUser;
import com.nineclock.system.service.SysCompanyUserService;
import com.nineclock.system.service.SysDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/organization")
public class OrganizationController  {

    @Autowired
    private SysCompanyUserService sysCompanyUserService;
    @Autowired
    private SysDepartmentService sysDepartmentService;


    @GetMapping("/members/simple")
    public Result<List<SysCompanyUser>> findAllUser() {
        List companyUserList = sysCompanyUserService.findAllUser();
        return Result.success(companyUserList);
    }


    @GetMapping("/department")

    public Result findDeptList() {
        return Result.success(sysDepartmentService.findDeptList());
    }


    @GetMapping("/members")
    public Result pageFindAll(Long page, Long pageSize, Long departmentId, String keyword) {
        PageResult pageResult = sysCompanyUserService.pageFindAll(page, pageSize, departmentId, keyword);
        return Result.success(pageResult);
    }
    @GetMapping("/simple")
    public Result simple(@RequestParam("id") Long id, @RequestParam("includeMember") int includeMember) {
        List<DepartmentOrUserSimpleDTO> departmentOrUserSimpleDTOList = sysDepartmentService.findDeptListByParentId(id);
        return Result.success(departmentOrUserSimpleDTOList);
    }


    @GetMapping("/simpleList")
    public Result FindAll(Long page, Long pageSize, Long includeMember) {
        PageResult pageResult = sysCompanyUserService.FindAll(page, pageSize, includeMember);
        return Result.success(pageResult);
    }

   /* *//**
     * 表格批量添加数据
     * @param
     * @param
     * @return
     */
    @PostMapping("/uploadExcel")
    public Result upExcel(MultipartFile excelFile){
        sysCompanyUserService.uploadUser(excelFile);
        return Result.success();

    }

}

